<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>物品列表</title>
    <!-- Bootstrap -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
          integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
    <link rel="stylesheet" href="http://localhost:8080/css/selllist.css">
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
    <div class="container-fluid">
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
                <form action="/goodslist" method="get">
                    <button type="submit" class="btn btn-info" style="margin-top: 8px;margin-right: 15px">首页</button>
                </form>
            </ul>
            <ul class="nav navbar-nav">
                <form action="/release" method="get">
                    <button type="submit" class="btn btn-info" style="margin-top: 8px">发布商品</button>
                </form>
            </ul>
            <ul class="nav navbar-nav navbar-right">
                <li>
                    <form action="/chatlist" method="get">
                        <button type="submit" class="btn btn-info" style="margin-top: 8px;margin-right: 10px">我的消息
                        </button>
                    </form>
                </li>
                <li>
                    <form action="/mysell" method="get">
                        <button type="submit" class="btn btn-info" style="margin-top: 8px;margin-right: 10px">我的发布
                        </button>
                    </form>
                </li>
                <li>
                    <form action="/mycollection" method="get">
                        <button type="submit" class="btn btn-info" style="margin-top: 8px;margin-right: 10px">我的关注
                        </button>
                    </form>
                </li>
                <li>
                    <form action="/logout" method="get">
                        <button type="submit" class="btn btn-info" style="margin-top: 8px;margin-right: 10px">退出登录
                        </button>
                    </form>
                </li>
            </ul>
        </div>
    </div>
</nav>
<br>
<section class="goodsBox w1200">
    <div class="container-fluid">
        <div class="row" id="info">

        </div>
    </div>
</section>

<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
<script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"
        integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ"
        crossorigin="anonymous"></script>
<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"
        integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd"
        crossorigin="anonymous"></script>

<script type="text/javascript">
    window.onload = function () {
        showInfo();
    }

    function getSellList() {
        let data;
        $.ajax({
            async: false,
            url: "/mysell",
            type: "POST",
            data: {},
            success: function (result) {
                data = result;
            },
            error: function () {
                alert("获取搜索数据失败");
            }
        });
        return data;
    }

    function deleteGood(id) {
        window.location.href = "/delete/" + id;
    }

    function showInfo() {
        let data;
        data = getSellList();

        let msg = "";

        for (let i in data) {
            let item = data[i];

            msg += "<div class=\"col-md-3\">\n" +
                "      <div class=\"goodsItemImgBox\">\n" +
                "           <img class=\"goodsItemImg\" src=\"" + item['imagePath'] + "\">\n" +
                "                </div>";
            msg += "<div class=\"goodsItemBottom\">\n" +
                "                    <div class=\"goodsItemName\">\n" +
                item['name'] + "\n" +
                "                    </div>";
            msg += "<div class=\"goodsItemDetail\">\n" +
                "                        <div class=\"goodsItemDetailLeft\">\n" +
                "                            <span class=\"goodsItemDetailLeft1\">￥" + item['price'];
            msg += "</span>\n" +
                "                            <span class=\"goodsItemDetailLeft2\">" + item['thumbNum'];
            msg += "人点赞</span>\n" +
                "                            <br>\n" +
                "                            <span class=\"goodsItemDetailLeft2\">" + item['commentNum'];
            msg += "条评论</span>\n" +
                "                        </div>\n" +
                "                        <div class=\"goodsItemDetailRight\">\n" +
                "                            <form>\n" +
                "                                <button type=\"button\" class=\"btn btn-primary\" onclick='deleteGood(" + item['id'] + ")'>立即下架</button>\n" +
                "                            </form>\n" +
                "                        </div>\n" +
                "                    </div>\n" +
                "                </div>\n" +
                "            </div>";
        }
        $("#info").html(msg);

    }
</script>

</body>
</html>